package com.wc.AlgoOJ.SQ1402;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/18 16:39
 * @description 黑暗料理
 * http://43.138.190.70:8888/p/SQ1402
 */
public class Main {
    static int N = 15;
    static int[] s = new int[N];
    static int[] b = new int[N];
    static PrintWriter out = new PrintWriter(System.out);
    static FastReader sc = new FastReader();
    static int n;
    static int ans = (int) 1e9 + 7;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            s[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        for (int i = 1; i <= n; i++) {
            dfs(1, s[i], b[i], i);
        }
        out.println(ans);
        out.flush();
    }

    static void dfs(int floor, int sSum, int bSum, int idx) {
        if (floor == n + 1) {
            ans = Math.min(ans, Math.abs(sSum - bSum));
            return;
        }
        dfs(floor + 1, sSum, bSum, idx);
        if (floor != idx)
            dfs(floor + 1, sSum * s[floor], bSum + b[floor], idx);
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
